package com.email.box.common.enums;

import java.util.Arrays;

/**
 * 数据库枚举类
 *
 * @author lixuan
 */

public enum DataBaseTypeEnum {
    //数据库类型
    MYSQL(1, "mysql"),
    SQL_SERVER(2, "sqlserver"),

    //jdbc_driver_class_name
    MYSQL_DRIVER_CLASS_NAME(101, "com.mysql.cj.jdbc.Driver"),
    MSSQL_DRIVER_CLASS_NAME(102, "com.microsoft.sqlserver.jdbc.SQLServerDriver"),

    //mysql_connection_url_tmp
    MYSQL_CONNECTION_URL_TMP(201, "jdbc:mysql:// host:port/db?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"),
    MSSQL_CONNECTION_URL_TMP(202, "jdbc:sqlserver:// host:port;DatabaseName=db;");

    private int code;
    private String message;


    DataBaseTypeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static String getDbTypeName(int code) {
        DataBaseTypeEnum messageEnum = DataBaseTypeEnum.getDataBaseTypeEnum(code);
        return messageEnum.getMessage();
    }

    public static DataBaseTypeEnum getDataBaseTypeEnum(int code) {
        return Arrays.stream(DataBaseTypeEnum.values()).filter(x -> x.code == code).findFirst().orElse(null);
    }
}
